﻿using System;
using System.Data;
using System.Web.UI.WebControls;

using HsTec.Mobile.Green.BLL;
using HsTec.Mobile.Green.Model;
using HsTec.Mobile.Green.Util;


public partial class ReportAnalysis_MonthlyReport : System.Web.UI.Page
{
    ReportAnalysisBLL bll = new ReportAnalysisBLL();
    ReportAnalysis model = new ReportAnalysis();
    private string sEditStatus = String.Empty;
    private string sID = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if ((string)Session["Baimasoft_Pers_ID"] == null)
        {
            Response.Redirect("../Logon.aspx");
        }
        try
        {
            sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
            if (sEditStatus == "2")
            {
                sID = this.Request.QueryString["ID"].ToString().Trim();
            }
        }
        catch
        {

        }
        if (!IsPostBack)
        {
            BindsltArea();
            try
            {
                if (sEditStatus == "2")
                {
                    model = bll.GetModel(int.Parse(sID));
                    this.sltArea.Value = model.Area_ID.ToString();
                    this.lblYears.Text = model.Years.ToString();

                    this.lblPowers.Text = model.Powers.ToString();
                    this.lblPowers_1.Text = model.Powers_1.ToString();
                    this.lblPowers_1_1.Text = model.Powers_1_1.ToString();
                    this.lblPowers_1_2.Text = model.Powers_1_2.ToString();
                    this.lblPowers_1_2_1.Text = model.Powers_1_2_1.ToString();
                    this.lblPowers_1_3.Text = model.Powers_1_3.ToString();
                    this.lblPowers_2.Text = model.Powers_2.ToString();
                    this.lblPowers_2_1.Text = model.Powers_2_1.ToString();
                    this.lblPowers_3.Text = model.Powers_3.ToString();
                    this.lblPowers_3_1.Text = model.Powers_3_1.ToString();
                    this.lblPowers_3_1_1.Text = model.Powers_3_1_1.ToString();
                    this.lblPowers_3_1_2.Text = model.Powers_3_1_2.ToString();
                    this.lblPowers_3_1_3.Text = model.Powers_3_1_3.ToString();
                    this.lblPowers_3_2.Text = model.Powers_3_2.ToString();
                    this.lblEnergy.Text = model.Energy.ToString();
                    this.lblEnergy_1.Text = model.Energy_1.ToString();
                    this.lblEnergy_2.Text = model.Energy_2.ToString();
                    this.lblEnergy_3.Text = model.Energy_3.ToString();
                    this.lblEnergy_4.Text = model.Energy_4.ToString();
                    this.lblBase.Text = model.Base.ToString();
                    this.lblBase_1.Text = model.Base_1.ToString();
                    this.lblBase_2.Text = model.Base_2.ToString();
                    this.lblBase_3.Text = model.Base_3.ToString();
                    this.lblBase_4.Text = model.Base_4.ToString();
                    this.lblBase_5.Text = model.Base_5.ToString();
                    this.lblBase_6.Text = model.Base_6.ToString();
                    this.lblBase_7.Text = model.Base_7.ToString();
                    this.lblBase_8.Text = model.Base_8.ToString();
                    this.lblBase_9.Text = model.Base_9.ToString();
                    this.lblBase_10.Text = model.Base_10.ToString();
                    this.lblOutdoor.Text = model.Outdoor.ToString();
                    this.lblIntelligent.Text = model.Intelligent.ToString();
                    this.lblIntelligent_1.Text = model.Intelligent_1.ToString();
                    this.lblIntelligent_2.Text = model.Intelligent_2;
                    this.lblIntelligent_3.Text = model.Intelligent_3.ToString();
                    this.lblSwitch.Text = model.Switch.ToString();
                    this.lblBatteries.Text = model.Batteries.ToString();
                    this.lblNewBase.Text = model.NewBase.ToString();
                    this.lblNewBase_1.Text = model.NewBase_1.ToString();
                    this.lblNewBase_2.Text = model.NewBase_2.ToString();
                    this.lblNewBase_3.Text = model.NewBase_3.ToString();
                    this.lblNewBase_4.Text = model.NewBase_4.ToString();
                    this.lblNewBase_5.Text = model.NewBase_5.ToString();
                    this.lblNewBase_6.Text = model.NewBase_6.ToString();
                    this.lblNewBase_7.Text = model.NewBase_7.ToString();
                    this.lblRecovery.Text = model.Recovery.ToString();
                    this.lblRecovery_1.Text = model.Recovery_1.ToString();
                    this.lblRecovery_2.Text = model.Recovery_2.ToString();
                    this.lblRecovery_3.Text = model.Recovery_3.ToString();
                    this.lblRecovery_4.Text = model.Recovery_4.ToString();
                    this.lblNewBatteries.Text = model.NewBatteries.ToString();
                    this.lblNewBatteries_1.Text = model.NewBatteries_1.ToString();
                    this.lblNewBatteries_2.Text = model.NewBatteries_2.ToString();
                    this.lblNewBatteries_3.Text = model.NewBatteries_3.ToString();
                    this.lblGreen.Text = model.Green.ToString();
                    this.lblGreen_1.Text = model.Green_1.ToString();
                    this.lblGreen_1_1.Text = model.Green_1_1.ToString();
                    this.lblGreen_2.Text = model.Green_2.ToString();
                    this.lblSIM.Text = model.SIM.ToString();
                    this.lblSIM_1.Text = model.SIM_1.ToString();
                    this.lblSIM_2.Text = model.SIM_2.ToString();
                    this.lblLighting.Text = model.Lighting.ToString();
                    this.lblLighting_1.Text = model.Lighting_1.ToString();
                    this.lblLighting_2.Text = model.Lighting_2.ToString();
                    this.lblLighting_3.Text = model.Lighting_3;
                    this.lblLighting_4.Text = model.Lighting_4.ToString();
                    this.lblLighting_5.Text = model.Lighting_5.ToString();
                    this.lblOther.Text = model.Other.ToString();
                    this.lblOther_1.Text = model.Other_1.ToString();
                    this.lblOther_2.Text = model.Other_2.ToString();
                    this.lblOther_3.Text = model.Other_3.ToString();
                    this.lblFunds.Text = model.Funds.ToString();
                    this.lblFunds_1.Text = model.Funds_1.ToString();
                    this.lblFunds_2.Text = model.Funds_2.ToString();
                    this.lblFunds_3.Text = model.Funds_3.ToString();
                    this.lblHarmonic.Text = model.Harmonic.ToString();

                    DataView mydv = bll.GetFillSpace(sID);
                    for (int i = 0; i < mydv.Count; i++)
                    {
                        Label lbl = (Label)this.FindControl("lbl" + mydv[i]["Subentry"].ToString());
                        lbl.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            catch
            {

            }
        }
    }
    private void BindsltArea()
    {
        sltArea.DataTextField = "Name";
        sltArea.DataValueField = "ID";
        sltArea.DataSource = bll.GetAreaList();
        sltArea.DataBind();
        sltArea.Items.Insert(0, "请选择县市区域...");
        sltArea.Items[0].Value = "";
    }
    protected void SaveData_ServerClick(object sender, EventArgs e)
    {
        int iBack = bll.FillSpaceNew(sID, sltArea.Value, lblYears.Text, Server.MapPath("ReportAnalysis.xml"));
        if (iBack == 1)
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('补空成功！');window.location.href='MonthlyReport.aspx?EditStatus=2&ID=" + sID + "';</script>");
        else if(iBack == 2)
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('没有设置补空比例，请进入补空比例设置页面！');</script>");
        else if (iBack == 3)
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('提供的数据不完整，无法补空，请添加部分数据后重新导入！');</script>");
        else if (iBack == 4)
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('数据已经补空请勿重复补空！');</script>");
        else
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('补空失败！');</script>");
    }
}
